Google News
logo
jQuery - Interview Questions
What is the use of css() method in JQuery?
The jQuery CSS() method is used to get (return)or set style properties or values for selected elements. It facilitates you to get one or more style properties. The jQuery CSS() provides two ways:
 
Return a CSS property

It is used to get the value of a specified CSS property.
 
$(document).ready(function(){    
    $("button").click(function(){    
        alert("Background color = " + $("p").css("background-color"));    
    });    
}); ​
   
 
Set a CSS property

This property is used to set a specific value for all matched element.
 
$(document).ready(function(){    
    $("button").click(function(){    
        $("p").css("background-color", "violet");    
    });    
});  
Advertisement